import { Cache } from "../../cache/Cache";
import { DirectionCopyConfig } from "../../resource/DirectionCopyConfig";
import { CopyConfig } from "../../resource/CopyConfig";
import { LaterUtil } from "../../../common/LaterUtil";
import { TCopy } from "../../../../Message/Db/Tables/TCopy";
import { ECopyType } from "../../../../Message/Public/ECopyType";
import { EActiveType } from "../../../../Message/Public/EActiveType";
import { GameConst } from "../../../component/gconst/GameConst";
import { DelegateConfig } from "../../resource/DelegateConfig";
import { ItemData } from "../../resource/info/ItemData";
import { EDifficultyOption } from "../../../../Message/Public/EDifficultyOption";
import { Language } from "../../../../extend/language/Language";
import { TGuildStruggleConfig } from "../../../../Message/Db/Tables/TGuildStruggleConfig";
import { SGuildStruggleInfo } from "../../../../Message/Public/SGuildStruggleInfo";
import { SGuildStruggleProcess } from "../../../../Message/Public/SGuildStruggleProcess";
import { ENpcEffect } from "../../../../Message/Public/ENpcEffect";
import { CopyCodeRule } from "../../rules/CopyCodeRule";
type int = number;
//class CopyUtil
    
    export  class CopyUtil
    {
        

        public static getCanOpenNextKingCopy(arg1: int): Boolean
        {
            var loc4=null;
            var loc1=int(Cache.instance.role.combatCapabilities);
            var loc2=Cache.instance.role.roleInfo.level;
            var loc3;
            if (loc3 = DirectionCopyConfig.instance.getItemByFloor(arg1)) 
            {
                if (loc4 = CopyConfig.instance.getInfoByCode(loc3.copyCode)) 
                {
                    return loc1 >= loc3.requireCombat && loc2 >= loc4.enterMinLevel;
                }
            }
            return false;
        }

        
        {
            CopyUtil._releaseKey = 0;
        }

        public static getReleaseKey(): string
        {
            CopyUtil._releaseKey = CopyUtil._releaseKey + 1;
            return LaterUtil.CopyRelease + "_" + CopyUtil._releaseKey;
        }

        public static isCopy(arg1: TCopy): Boolean
        {
            if (arg1) 
            {
                var loc1=arg1.copyType;
                switch (loc1) 
                {
                    case ECopyType._ECopyNormal: case ECopyType._ECopyTower: case ECopyType._ECopyDefense: case ECopyType._ECopyCoin: case ECopyType._ECopySixty: case ECopyType._ECopyFairyland: case ECopyType._ECopySeventy: case ECopyType._ECopy60Defense: case ECopyType._ECopyEighty:
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public static isCrossCopy(arg1: TCopy): Boolean
        {
            if (arg1) 
            {
                var loc1=arg1.copyType;
                switch (loc1) 
                {
                    case ECopyType._ECopyCrossDefense: case ECopyType._ECopyCrossSecret: case ECopyType._ECopyUpgradeCrossSecret: case ECopyType._ECopyCrossTower:
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public static getCopyNumByDay(arg1): int
        {
            var loc1=null;
            if (typeof arg1 === "tcopy") 
            {
                loc1 = arg1 as TCopy;
            }
            else if (typeof arg1 === "int") 
            {
                loc1 = CopyConfig.instance.getInfoByCode(arg1);
            }
            if (loc1 == null) 
            {
                return 0;
            }
            if (Cache.instance.active.isActiveInEffect(EActiveType._EActiveTypeCrossCopyExtraTimes)) 
            {
                if (Cache.instance.copy.isInKingCopy(loc1) || loc1.copyType == ECopyType._ECopyCrossDefense || loc1.copyType == ECopyType._ECopyCrossSecret || loc1.copyType == ECopyType._ECopyUpgradeCrossSecret) 
                {
                    return loc1.numByDay + GameConst.CrossCopyExtraTimes;
                }
                return loc1.numByDay;
            }
            return loc1.numByDay;
        }

        public static hasPracticeNum(arg1: int): Boolean
        {
            var loc1=Cache.instance.copy.getCopyNumInfoByCode(arg1);
            if (loc1) 
            {
                return loc1.totalPracticeTime > 0;
            }
            return false;
        }

        public static isCanDelegate(arg1: TCopy): Boolean
        {
            if (arg1 && DelegateConfig.instance.getInfoByCopyCode(arg1.code)) 
            {
                return true;
            }
            return false;
        }

        public static isDefenceDelegate(arg1: TCopy): Boolean
        {
            return arg1 && (arg1.copyType == ECopyType._ECopy60Defense || arg1.copyType == ECopyType._ECopyDefense || arg1.copyType == ECopyType._ECopy80Defense);
        }

        public static isHighestDefenceCopy(arg1: TCopy): Boolean
        {
            return arg1 && arg1.copyType == ECopyType._ECopy80Defense;
        }

        public static isCanFreeDelegate(arg1: TCopy): Boolean
        {
            if (arg1.copyType == ECopyType._ECopyCrossDefense) 
            {
                return false;
            }
            if (CopyUtil.isCanDelegate(arg1) && Cache.instance.role.roleInfo.level - arg1.enterMinLevel >= 20) 
            {
                return true;
            }
            return false;
        }

        public static isCanDelegateByCopyId(arg1: int): Boolean
        {
            var loc1=CopyConfig.instance.getInfoByCode(arg1);
            if (loc1) 
            {
                return CopyUtil.isCanDelegate(loc1);
            }
            return false;
        }

        public static getCopyRewards(arg1: TCopy): Array<any>
        {
            var loc4=0;
            if (!arg1) 
            {
                return [];
            }
            var loc1=[];
            var loc2=arg1.reward.split(",");
            var loc3=0;
            while (loc3 < loc2.length) 
            {
                if (loc2[loc3] != "") 
                {
                    if ((loc4 = Number(loc2[loc3])) != 0) 
                    {
                        loc1.push(new ItemData(loc4));
                    }
                }
                ++loc3;
            }
            return loc1;
        }

        public static getCopyNpc(arg1: TCopy): int
        {
            var loc1=null;
            if (arg1.npc && !(arg1.npc == "")) 
            {
                loc1 = arg1.npc.split("#");
                return parseInt(loc1[0]);
            }
            return 0;
        }

        public static getCopyName(arg1: TCopy): string
        {
            if (arg1) 
            {
                return arg1.name;
            }
            return "";
        }

        public static getDifficultyDef(arg1: int): string
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case EDifficultyOption._EDifficultyEasy:
                {
                    return Language.getString(60403);
                }
                case EDifficultyOption._EDifficultyNormal:
                {
                    return Language.getString(60404);
                }
                case EDifficultyOption._EDifficultyHard:
                {
                    return Language.getString(60405);
                }
                case EDifficultyOption._EDifficultySerious:
                {
                    return Language.getString(60406);
                }
            }
            return "";
        }

        public static getDifficultyPlayerDef(arg1: int): string
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case EDifficultyOption._EDifficultyEasy:
                {
                    return Language.getString(60423);
                }
                case EDifficultyOption._EDifficultyNormal:
                {
                    return Language.getString(60424);
                }
                case EDifficultyOption._EDifficultyHard:
                {
                    return Language.getString(60425);
                }
                case EDifficultyOption._EDifficultySerious:
                {
                    return Language.getString(60425);
                }
            }
            return "";
        }

        public static getGuildCopyBossList(arg1: TGuildStruggleConfig): Array<any>
        {
            var loc3=null;
            var loc4=null;
            var loc1=[];
            var loc2=arg1.targetBosses.split("#");
            var loc5=0;
            var loc6=loc2;
            for(loc3 of loc6) 
            {
                if ((loc4 = loc3.split(",")).length != 3) 
                {
                    continue;
                }
                loc1.push({"bossCode": loc4[1], "bossNum": loc4[2]});
            }
            return loc1;
        }

        public static getGuildCopyItemList(arg1: TGuildStruggleConfig): Array<any>
        {
            var loc1=[];
            var loc2=arg1.targetItems.split("#")[0].split(",");
            if (loc2.length == 3) 
            {
                loc1.push({"itemCode": loc2[1], "itemNum": loc2[2]});
            }
            return loc1;
        }

        public static isGuildCopyWuxingBossEnd(arg1: SGuildStruggleInfo, arg2: SGuildStruggleProcess, arg3: TGuildStruggleConfig): Boolean
        {
            var loc2=0;
            var loc3=0;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc1=true;
            if (arg1.layer == 1) 
            {
                loc6 = CopyUtil.getGuildCopyBossList(arg3);
                loc3 = 0;
                while (loc3 < loc6.length) 
                {
                    loc4 = loc6[loc3];
                    loc2 = 0;
                    var loc7=0;
                    var loc8=arg2.killBosses;
                    for(loc5 of loc8) 
                    {
                        if (loc5.code != loc4["bossCode"]) 
                        {
                            continue;
                        }
                        loc2 = loc5.num;
                        break;
                    }
                    if (loc4["bossNum"] > 1 && loc2 < loc4["bossNum"]) 
                    {
                        loc1 = false;
                    }
                    ++loc3;
                }
            }
            return loc1;
        }

        public static checkCanNotEnterHardCopy(arg1: int): Boolean
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case ENpcEffect._ENpcEffectCrossDefenceCopyHard:
                {
                    if (!Cache.instance.copy.checkHadPassCopy(CopyCodeRule.Copy162)) 
                    {
                        return true;
                    }
                    return false;
                }
            }
            return false;
        }

        public static getArenaCrossWaitingRoomMapId(): int
        {
            return CopyConfig.instance.getInfoByCode(GameConst.ArenaCrossCopyCode).intoMapId;
        }

        public static getGangFightsWaitingRoomMapId(): int
        {
            return CopyConfig.instance.getInfoByCode(GameConst.GangFightsCopyCode).intoMapId;
        }

        public static getCrossSpiritWarCopyMapId(): int
        {
            return CopyConfig.instance.getInfoByCode(GameConst.CrossSpiritWarCopyCode).intoMapId;
        }

        public static getWrestleWaitingRoomMapId(): int
        {
            return CopyConfig.instance.getInfoByCode(GameConst.WrestleCopyCode).intoMapId;
        }

        public static getArenaWaitingRoomMapId(): int
        {
            return CopyConfig.instance.getInfoByCode(GameConst.ArenaCopyCode).intoMapId;
        }

        public static getCrossMainCityMapId(): int
        {
            return CopyConfig.instance.getInfoByCode(160).intoMapId;
        }

        public static getCrossDefenceCopyMapId(): int
        {
            return CopyConfig.instance.getInfoByCode(162).intoMapId;
        }

        public static getCrossDefenceDifficultCopyMapId(): int
        {
            return CopyConfig.instance.getInfoByCode(164).intoMapId;
        }

        public static getGodSpeedwayCopyMapId(): int
        {
            return CopyConfig.instance.getInfoByCode(152).intoMapId;
        }

        public static getCrossGuildWarWaittingRoomMapId(): int
        {
            return CopyConfig.instance.getInfoByCode(182).intoMapId;
        }

        public static /* var */toWhichFloor: int;

        /* internal */ static /* var */_releaseKey: int=0;
    }
